package com.aaa.rabbitmq.two;

import com.aaa.rabbitmq.one.util.RabbitMQUtil;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.Scanner;

/**
 *
 * 生产者
 * zhc
 */
public class Task01 {

    //队列名称
    public static final String QUEUE_NAME="hello";

    //发消息
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtil.getChannel();
        //创建队列
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);

        //从控制台拿到消息发送上去
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String msg = scanner.next();
            //用信道 发消息
            channel.basicPublish("",QUEUE_NAME,null,msg.getBytes(StandardCharsets.UTF_8));
            System.out.println("发送消息完成");
        }

    }
}
